package com.longge;

import java.util.HashSet;

public class FindMissingAndRepeatedValues {

    public int[] findMissingAndRepeatedValues(int[][] grid) {

        HashSet<Integer> set = new HashSet<>();
        int dup = 0;
        int n = grid.length;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (!set.add(grid[i][j])) {
                    dup = grid[i][j];
                }
            }
        }
        int lose = 0;
        for (int i = 1; i <= n * n; i++) {
            if (!set.contains(i)) {
                lose = i;
            }
        }
        return new int[]{dup,lose};
    }
}
